from flask import Flask, request
from gevent import pywsgi
import json
from buss.eq import eq
from buss.calc import calc
from buss.pyShell import pyShell
from buss.spider import chinafcd
from buss.lunar import is_lunar, lunar_filter, cur_lunar

app = Flask(__name__)

@app.route('/eq_calc', methods=["POST"])
def eq_calc():
    return json.dumps(eq(json.loads(request.get_data().decode('utf-8'))))

@app.route('/calc_calc', methods=["POST"])
def int_calc():
    return json.dumps(calc(json.loads(request.get_data().decode('utf-8'))))

@app.route('/pyshell', methods=["POST"])
def pyshell():
    return json.dumps(pyShell(json.loads(request.get_data().decode('utf-8'))))

@app.route('/food', methods=["POST"])
def food():
    return json.dumps(chinafcd(json.loads(request.get_data().decode('utf-8'))))

@app.route('/is_lunar', methods=["POST"])
def isLunar():
    return json.dumps(is_lunar(json.loads(request.get_data().decode('utf-8'))))

@app.route('/lunar_filter', methods=["POST"])
def lunarFilter():
    return json.dumps(lunar_filter(json.loads(request.get_data().decode('utf-8'))))

@app.route('/cur_lunar', methods=["GET"])
def curLunar():
    return json.dumps(cur_lunar())

if __name__ == "__main__":
    server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
    print('success')
    server.serve_forever()

